#!/usr/bin/env python
#SCsub


import os
from tools import helpers, openssl, boost



##### ENVIROMENT #####

Import('env')
mysql_env = env.Clone()

# You don't have to compile third-party libraries each time you compile the module.
# With the "recompile" option you can recompile just Openssl or just Boost, both of them or none of them.
opts = Variables(["customs.py"], ARGUMENTS)
opts.Add(EnumVariable("recompile_sql", "Recompile third party library", "all", ("all", "openssl", "boost", "none")))
opts.Update(mysql_env)



##### FLAGS #####

# Enable Boost separate compilation mode
#mysql_env.Append(CPPDEFINES=["BOOST_MYSQL_SEPARATE_COMPILATION"])

# Build with exceptions!
#if env["disable_exceptions"]:
#	if env.msvc and ("_HAS_EXCEPTIONS", 0) in mysql_env["CPPDEFINES"]:
#		mysql_env["CPPDEFINES"].remove(("_HAS_EXCEPTIONS", 0))
#		mysql_env.AppendUnique(CPPFLAGS=["/EHsc"])
#	elif not env.msvc and "-fno-exceptions" in mysql_env["CPPFLAGS"]:
#		mysql_env["CPPFLAGS"].remove("-fno-exceptions")

mysql_env.Append(CPPFLAGS=[
	'-fexceptions',
	'-std=c++20',
])

target_bits = "64" if env["arch"] in ["x86_64", "arm64", "rv64", "ppc64"] else "32"



##### PATHS #####

# Use absolut paths to avoid problem between platforms.
# dep_path = os.path.join(os.getcwd(), "3party")

openssl_path = openssl.get_openssl_install_path(mysql_env)
openssl_include_path = openssl_path + "/include"
openssl_lib_path = openssl_path + "/lib64"
boost_path = boost.get_boost_install_path(mysql_env)
boost_include_path = boost_path + "/include"
boost_lib_path = boost_path + "/stage/lib"


##### THIRDPARTY COMPILATION #####

# Update and compile thirdparty.
helpers.apply_config(mysql_env)



##### GODOT MODULE #####

# INCLUDE:
mysql_env.Prepend(CPPPATH=[
	openssl_include_path,
	boost_include_path,
#	openssl_path
])

# LIB
env.Prepend(LIBPATH=[
	openssl_lib_path,
	boost_lib_path,
#	openssl_path
])

mysql_env.add_source_files(env.modules_sources, "*.cpp")
mysql_env.add_source_files(env.modules_sources, "scr/**.cpp")


env.Prepend(LIBS=["libboost_thread", "libcrypto", "libssl"])






